using System;
using System.Collections.Generic;
using Commons.Models.Definitions;

namespace Commons.Models.Settings
{
	[Serializable]
	public class HighScoreSettings : ISettings
	{
		private Dictionary<int, HighScoreDefinition> definitions = new Dictionary<int, HighScoreDefinition>();

		public HighScoreSettings(IEnumerable<HighScoreDefinition> definitions)
		{
			this.definitions = new Dictionary<int, HighScoreDefinition>();
			foreach (HighScoreDefinition definition in definitions)
			{
				this.definitions.Add(definition.Code, definition);
			}
		}

		public IEnumerable<HighScoreDefinition> GetDefinitions()
		{
			return definitions.Values;
		}

		public HighScoreDefinition GetDefinition(int code)
		{
			HighScoreDefinition definition;
			if (definitions.TryGetValue(code, out definition))
			{
				return definition;
			}
			else
			{
				throw new Exception("No highscore with code " + code);
			}
		}
	}
}

